    <div class="container">
      <div class="bg-putih">

        <div class="jdl-page">
          <?php echo isset($judul)?$judul:'<font color="#ccc">Judul Belum Diberikan</font>'; ?>
          <div class="clearfix"></div>
        </div>

        <?php echo form_open(site_url('obat_analisa/analize'), array('class' => 'form-horizontal', 'role' => 'form', 'id' => 'form')); ?>
        <script type="text/javascript">
          $(document).ready(function() {
            $(".obat").select2();
          });
        </script>        
        <table class="table table-striped table-hover">
          <thead>
            <tr>
              <th width="80%">Nama Obat</th>
              <th width="15%">Dosis</th>
              <th width="5%"></th>
            </tr>
          </thead>
          <tbody id="tbl-analisa">            
            <tr>
              <td>
                <select class="form-control obat" name="obat[]">
                  <?php
                  foreach($obat as $value) {
                    echo "<option value=$value[KdObat]>$value[NmObat]</option>";
                  }
                  ?>
                </select>
              </td>
              <td>
                <input type="text" name="dosis[]" class="form-control input-sm" value="0"/>
              </td>
              <td>
              </td>
            </tr>                       
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3" align="right">
                <a href="javascript:add_data()" onclick="" class="btn btn-success btn-sm">
                  <i class="fa fa-fw fa-plus"></i> Tambah Record
                </a>
                <input type="submit" name="btn_analize" value="Mulai Analisa" class="btn btn-sm btn-primary"/>
              </td>
            </tr>            
          </tfoot>
        </table>
        <?php echo form_close(); ?>
        <div class="clearfix"></div>
      </div>
    </div> <!-- /container -->

    <script>
     $("#form").validate({
      rules: {
        obat1: {
          required: true
        },
        obat2: {
          required: true         
        },
        interaksi: {
          required: true         
        }
      }
    });
   </script>
   <script type="text/javascript">
    function hapusData(obj){  
      if (confirm('Apakah data akan dihapus ?')) {
        obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
      }
    }

    function add_data(){
      var tampil_tombol_aksi = '<a href="javascript:void(null)" class="btn btn-sm btn-danger" title="Hapus" onclick="hapusData(this)"><i class="fa fa-trash-o"></i></a>';
      var tr = document.createElement('tr');
      var td_obat = document.createElement('td');
      var td_dosis = document.createElement('td');     
      var td_aksi = document.createElement('td');     
      var tbodi = document.getElementById("tbl-analisa");

      td_aksi.className = 'links';
      td_obat.innerHTML = "<select class='form-control obat' name='obat[]'><?php foreach($obat as $value) { echo "<option value='$value[KdObat]'>$value[NmObat]</option>";}?></select>";
      td_dosis.innerHTML = '<input type="text" name="dosis[]" class="form-control input-sm" value="0"/>';
      td_aksi.innerHTML = tampil_tombol_aksi;
      tr.appendChild(td_obat);
      tr.appendChild(td_dosis);
      tr.appendChild(td_aksi);
      tbodi.appendChild(tr);
      $(".obat").select2(); //Mengubah form .obat menjadi select2 pada saat klik tombol tambah
    }
  </script>
  
  <script type="text/javascript">
    function pilih(id){
      alert(id);
    }
  </script>